package se.perp.c4.model;

public class Game {

    public Actor.Side whoseTurn;
    public Actor.Side mySide,  opponentSide;
    public int round,  myScore,  opponentScore;
    private static String[] descriptions = {
        "If Shelob wins a battle outside of Gondor, and Gondor is either occupied by two dark characters or at least one light character, Shelob cannot return and will instead die instantly.\n\n(Rule interpretation from the official deluxe edition rules.)",
        "If Shelob wins a battle outside of Gondor, and Gondor is occupied by light characters, Shelob returns and fights them instantly. If Gondor is occupied by two dark characters, Shelob dies.\n\n(Rule interpretation from the offical FAQ.)",
        "If Shelob wins a battle outside of Gondor, and Gondor is either occupied by two dark characters or at least one light character, Shelob does not return but stays in the same region as the battle took place.\n\n(Homebrew interpretation.)"
    };
    private static String[] cutDescriptions = {
        "If Shelob wins a battle outside of Gondor, and Gondor is\n" +
        "either occupied by two dark characters or at least one\n" +
        "light character, Shelob cannot return and will instead \n" +
        "die instantly.",
        "If Shelob wins a battle outside of Gondor, and Gondor is\n" +
        "occupied by light characters, Shelob returns and fights\n" +
        "them instantly. If Gondor is occupied by two dark\n" +
        "characters, Shelob dies.",
        "If Shelob wins a battle outside of Gondor, and Gondor is\n" +
        "either occupied by two dark characters or at least one\n" +
        "light character, Shelob does not return but stays in the\n" +
        "same region as the battle took place."
    };

    public enum ShelobRule {

        /** If Gondor is full or occupied by light, Shelob can't return and dies. */
        SHELOB_DIES,
        /** If Gondor is occupied by light, she returns and fights them. */
        SHELOB_FIGHTS_OR_DIES,
        /** If Gondor is full or occupied by light, Shelob does not return. */
        SHELOB_STAYS
    }
    public ShelobRule shelobRule = ShelobRule.SHELOB_STAYS;

    public static String shelobRuleString(ShelobRule rule) {
        switch (rule) {
            case SHELOB_DIES:
                return "Shelob DIES";
            case SHELOB_FIGHTS_OR_DIES:
                return "Shelob FIGHTS";
            case SHELOB_STAYS:
                return "Shelob STAYS";
            default:
                throw new RuntimeException("Invalid rule.");
        }
    }

    public static String shelobRuleDescription(ShelobRule rule) {
        return descriptions[rule.ordinal()];
    }

    public static String shelobCutRuleDescr(ShelobRule rule) {
        return cutDescriptions[rule.ordinal()];
    }

    public Game() {
        round = 0;
        myScore = 0;
        opponentScore = 0;

        whoseTurn = Actor.Side.DARK;

        if ((int) (Math.random() * 100) > 49) {
            mySide = Actor.Side.DARK;
            opponentSide = Actor.Side.LIGHT;
        } else {
            mySide = Actor.Side.LIGHT;
            opponentSide = Actor.Side.DARK;
        }
    }

    public boolean myTurn() {
        return (whoseTurn == mySide);
    }

    public void nextTurn() {
        if (whoseTurn == Actor.Side.DARK) {
            whoseTurn = Actor.Side.LIGHT;
        } else {
            whoseTurn = Actor.Side.DARK;
        }
    }
}
